#coding=utf-8
from collections  import OrderedDict
import json
import urllib
import urllib2

from Crypto.Cipher import AES

dt=OrderedDict()
dt['origChanId']='xiaomi'
dt['appId']='A0008'
dt['ts']='1459936625905'
dt['netModel']='w'
dt['chanId']='guanwang'
dt['imei']='357541051318147'
dt['qid']=''
dt['mac']='e8:92:a4:9b:16:42'
dt['capSsid']='hijack'
dt['lang']='cn'
dt['longi']='103.985752'
dt['nbaps']=''
dt['capBssid']='b0:d5:9d:45:b9:85'
dt['bssid']='b0:d5:9d:56:82:10'
dt['mapSP']='t'
dt['userToken']=''
dt['verName']='4.1.8'
dt['ssid']='360WiFi-1你好'
dt['verCode']='3028'
dt['sign']='A8DB02E23BD2C3FCE2833AE64F17F9A6'
dt['uhid']='a0000000000000000000000000000001'
dt['lati']='30.579577'
dt['dhid']='9374df1b6a3c4072a0271d52cbb2c7b6'
dt=json.dumps(dt,ensure_ascii=False,separators=(',',':'))
dt=urllib.quote(dt)
j=len(dt)
i=0
while(i<16-j%16):
    dt=dt+' '
    i=i+1
cipher=AES.new(b"!I50#LSSciCx&q6E",AES.MODE_CBC,b"$t%s%12#2b474pXF")
ed=cipher.encrypt(dt).encode('hex').upper()

header = {'Content-Type': 'application/json'}
request =urllib2.Request(url='http://sso.51y5.net/sso/fa.sec',headers=header,data=dt)
response = urllib2.urlopen(request)

print type(response)
print response.info

hjson = json.loads(response.read())
print hjson

cipher0=AES.new(b"1234567891013156",AES.MODE_ECB,b"1234567891113156")
ed0=cipher.encrypt(dt).encode('hex').upper()
print ed0
